package com.yanqu.road.dao.impl.activity.wishpool;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDataObjectDao;
import com.yanqu.road.entity.activity.wishpool.WishPoolBigReward;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 许愿池配置大奖
 */
public class WishPoolRewardDaoImpl extends TempDataObjectDao<WishPoolBigReward> {

    public static String getWishPoolBigRewardListSql = "select * from t_s_activity_wish_pool_reward where activityId=? order by id asc";

    public List<WishPoolBigReward> getWishPoolBigRewardList(int activityId) {
        List<WishPoolBigReward> dataList = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getWishPoolBigRewardListSql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                dataList.add(parseData(rs));
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataList;
    }

    @Override
    protected boolean addData(WishPoolBigReward data) {
        return false;
    }

    @Override
    protected boolean updateData(WishPoolBigReward data) {
        return false;
    }

    @Override
    protected WishPoolBigReward parseData(ResultSet rs) throws SQLException {
        WishPoolBigReward wishPoolBigReward = new WishPoolBigReward();
        wishPoolBigReward.setActivityId(rs.getInt("activityId"));
        wishPoolBigReward.setId(rs.getInt("id"));
        wishPoolBigReward.setWishValue(rs.getInt("wishValue"));
        wishPoolBigReward.setRewardList(rs.getString("rewardList"));
        return wishPoolBigReward;
    }
}
